<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #img1 {
            background-position: -7px -28px;
        }

        #img2 {
            background-position: -7px -28px;
        }

        #img3 {
            background-position: -7px -28px;
        }

        #img4 {
            background-position: -7px -28px;
        }

        #img5 {
            background-position: -7px -28px;
        }

        li {
            width: 20px;
            height: 20px;
            background: url(img/star.png) no-repeat;
            display: inline-block;
            cursor: pointer;
        }

        .qh {
            background-position: -7px -8px !important;

        }

        p {
            margin-left: 40px;
            font-size: 24px;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li id="img1"></li>
            <li id="img2"></li>
            <li id="img3"></li>
            <li id="img4"></li>
            <li id="img5"></li>
        </ul>
        <p>0颗星</p>
    </div>
    <script>
        var ul1 = document.querySelector('ul')
        var p1 = document.querySelector('p')
        var lis = document.querySelectorAll('li')
        ul1.addEventListener('click', djFun)

        function djFun(event) {
            if (event.target.nodeName == "LI") {
                for (var i = 0; i < lis.length; i++) {
                    lis[i].classList.remove("qh")
                }
                for (var i = 0; i < lis.length; i++) {
                    lis[i].classList.add("qh")
                    p1.innerHTML = (i + 1) + "颗星"
                    if (event.target.id == lis[i].id) {
                        return
                    }
                }
            }
        }
    </script>
</body>

</html>